﻿using ANPR_MX.MainControl;
using Interfaces;
using Ninject.Modules;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ANPRMXEngine
{
    public class ANPRMXRecEngine : NinjectModule, IRecognitionEngine
    {
        string tmppath;
        string[] plates = new string[] { };
        ImageProcessing processor;
        Bitmap plate = null;

        public ANPRMXRecEngine(): this(new ImageProcessing())
        {
        }

        public ANPRMXRecEngine(ImageProcessing processor)
        {
            this.processor = processor;
            this.tmppath = Path.Combine(Directory.GetCurrentDirectory(), "tmp.jpg");
        }

        public string GetPlateNum(Bitmap image)
        {
            image.Save(tmppath, System.Drawing.Imaging.ImageFormat.Jpeg);

            plate = processor.ProcessImage(tmppath, out plates);

            File.Delete(tmppath);
            return plates[0];
        }

        public string[] GetAlternateMatches()
        {
            return plates.Skip(1).ToArray();
        }

        public System.Drawing.Bitmap GetPlatePatch()
        {
            return plate;
        }

        public override void Load()
        {
            Bind<IRecognitionEngine>().To<ANPRMXRecEngine>();
        }
    }
}
